#ifndef _DSW3GP_H
#define _DSW3GP_H

#include <libbase/dswbase.h>

class CDsw3gp : public CDswbase
{
public:
	CDsw3gp(LPST_ENV_T pEnv);
	CDsw3gp(LPST_ENV_T pEnv, MP4FileHandle h3gp);
	virtual ~CDsw3gp();
public:
	static CDsw3gp* createNewZtime(LPST_ENV_T pEnv, bool bLocal, int nCh, char* pZtime);
	bool Create3GPFile(char* pFileName, char* pSps, int* pSpsLen, char* pPps, int* pPpsLen, int nFps);
	bool WriteVideoFrame(bool bKeyFrame, char* pFrame, int nLen);
	
	static bool ConvertDataFile23gpFile(char* pTmpDataFile, char* p3GPFileName, bool* pbStop, char* pSaveFrameBuffer);
	static CDsw3gp* createNew(LPST_ENV_T pEnv, char* p3GPFileName);
	void GetStoreFileResolution(int &nWidth, int &nHeight, int &nBitrate, int &nFps, int &nDuration);
	void SetOffset(int nSeconds);
	bool ReadFrame(unsigned char* pFrame, int &nLen, bool &bKeyFrame);

	bool Reload3GPFile(char* pFileName, int &nWidth, int &nHeight, int &nBitrate, int &nFps, int &nDuration);
	void Close3GPFile();
	bool IsValid3GPFile(){return (m_h3gp != MP4_INVALID_FILE_HANDLE);};
private:
	LPST_ENV_T m_pEnv;
	
	int m_nWidth, m_nHeight, m_nFps, m_nBitrate;
	int m_nTotalFrames;
	MP4FileHandle m_h3gp;
	uint8_t **m_pSps, **m_pPps;
	uint32_t *m_pSpsLen, *m_pPpsLen;
	int m_nCurFrameId;

	int m_nVideoTrackId;
	MP4Duration m_nFrameDuration;
};

#endif

